<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class News extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->headerdata = array();
		if (($this->session->userdata('userid')>0) && ($this->session->userdata('hash')==md5($this->session->userdata('userid').$this->session->userdata('username')))){
			$this->headerdata['userid'] = $this->session->userdata('userid');
			$this->headerdata['username'] = $this->session->userdata('username');
		}else{
			$this->headerdata['userid'] = 0;
			$this->headerdata['username'] = 'Guest';
		}
		
		$this->headerdata['route'] = 'ThucTap.com';
		$this->headerdata['routelink'] = '';
		$this->headerdata['route2'] = 'Tin tức';
		$this->headerdata['route2link'] = 'news';
		
		if ($this->session->userdata('userid')==0) redirect(site_url());
	}
	
	function index(){
		redirect(site_url());
	}
	
	function detail($id){
		if (!isset($id) || !is_numeric($id) || ($id < 1)) redirect(site_url());
		
		$data = array();
		$this->load->model('NewsModel');
		$data['news'] = $this->NewsModel->get($id);
		
		$this->headerdata['route3'] = $data['news']->title;
		
		$this->load->view('common/header',$this->headerdata);
		$this->load->view('common/left');
		$this->load->view('news_detail',$data);
		$this->load->view('common/footer');
	}
}
?>